% GAUTIER LE BIHAN - 2020
% Replication files for "Shocks vs Menu Costs: Patterns of Price Rigidity in an Estimated Multi-Sector Menu-Cost Model?" Review of Economics and Statistics
%
% This code produces Table D
clear;
tic
addpath('..\..\Utilities')  

load actual_moments_k
weight=actual_moments_k(:,12);
sum(weight)
secteur=actual_moments_k(:,1);

load ..\..\Simulations_VC\MS_produits_MC\stat4
param=stat4;

data=param(:,5:9)
%
load ..\..\Simulations_VC\Counterfactual_sim\MS_produits_MC\stat_simu_out.mat

for jj=2:3
    
    data_sim=stat_simu_out(jj).stat_simu_out(:,5:9);
    
    
for i=1:5
y=[data_sim(:,i) data(:,i)];
y=[data(:,i) data_sim(:,i)];

% r1 = corrcoef(y) 
% corr(i)=r1(2,1)% Traditional Correlation Matrix 
% r2 = weightedcorrs(y, weight) % Weighted Correlation Matrix
% corrw(i)=r2(2,1)% Traditional Correlation Matrix 

%p(i,:) = polyfit(y(:,1),y(:,2),1)
lm = fitlm(y(:,1),y(:,2))
p(i,:)=lm.Coefficients(2,1)
v(i,:)=lm.Coefficients(2,4)
y_he=[data((secteur ~=5),i) data_sim((secteur ~=5),i)];

% r1 = corrcoef(y_he) 
% corrhe(i)=r1(2,1)% Traditional Correlation Matrix 
% 
% r2 = weightedcorrs(y_he, weight((secteur ~=5))) % Weighted Correlation Matrix
% corrw_he(i)=r2(2,1)% Traditional Correlation Matrix 
%phe(i,:) = polyfit(y_he(:,1),y_he(:,2),1)
lm = fitlm(y_he(:,1),y_he(:,2))
phe(i,:)=lm.Coefficients(2,1)
vhe(i,:)=lm.Coefficients(2,4)
end
%corrt(jj,:)=corr;
%corrthe(jj,:)=corrhe;

%corrtw(jj,:)=corrw;
%corrthew(jj,:)=corrw_he;

p_tot(:,jj-1)=p(:,1)
phe_tot(:,jj-1)=phe(:,1)

v_tot(:,jj-1)=v(:,1)
vhe_tot(:,jj-1)=vhe(:,1)


end
% corrtw
% corrthew
% 
% 
% corrt
% 
% corrthe